package com.cn.wanxi.service;

import com.cn.wanxi.IO.CompanyIO;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.util.ReadNote;
import com.cn.wanxi.util.Tool;

public class CompanyService {


    /**
     * 公司信息服务逻辑层
     * 封装公司信息代码
     *
     * @return
     */
    public CompanyModel getCompanyModel() {
        String path = String.valueOf(Tool.companyPath.getPath());
        CompanyIO companyIO = new CompanyIO();
        companyIO.writeNote(path);//写入记事本
        String string = ReadNote.read(path);//读取记事本内容
        return getCompanyModelFromNote(string);
    }

    /**
     * 封装公司信息数据
     *
     * @param string
     * @return
     */
    private CompanyModel getCompanyModelFromNote(String string) {
        String[] companyString = string.split(Tool.split.getPath());//将读取出来的数据分隔成数组
//        System.out.println(Arrays.toString(companyString));
//        Arrays.toString(companyString)打印数组,数组下标从0开始
//        现在需要将字符串封装到companyModel
        CompanyModel companyModel = new CompanyModel();//实例化一个空的公司model
        companyModel.setLogo(companyString[0]);
        companyModel.setAddress(companyString[1]);
        companyModel.setPhone(companyString[2]);
        companyModel.setAd(companyString[3]);
        companyModel.setNet(companyString[4]);
        companyModel.setEmail(companyString[5]);
        companyModel.setLinePhone(companyString[6]);
        companyModel.setVersion(companyString[7]);
        companyModel.setContent(companyString[8]);
        return companyModel;
    }

}
